package org.fanfan.struts.actionForms;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class ListForm extends ActionForm {
	private List<String> addresses = new ArrayList<String>();
	private List<String> friends = new ArrayList<String>();
	
	@Override
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		super.reset(mapping, request);
		addresses.clear();
		friends.clear();
	}

	public List<String> getAddresses() {
		return addresses;
	}
	
	public String getAddress(int index){
		if(addresses.size() > index){
			return addresses.get(index);
		}
		return null;
	}
	
	public void setAddresses(List<String> addresses) {
		this.addresses = addresses;
	}
	
	public void setAddress(int index, String addr){
		if(addresses.size() > index){
			addresses.set(index, addr);
		}else{
			while(addresses.size() < index){
				addresses.add(null);
			}
			addresses.add(index, addr);
		}
	}
	
	public List<String> getFriends() {
		return friends;
	}
	
	public String getFriend(int index){
		if(friends.size() > index){
			return friends.get(index);
		}
		return null;
	}
	
	public void setFriends(List<String> friends) {
		this.friends = friends;
	}
	
	public void setFriend(int index, String friend){
		if(friends.size() > index){
			friends.set(index, friend);
		}else{
			while(friends.size() < index){
				friends.add(null);
			}
			friends.add(index, friend);
		}
	}
	
}
